﻿using HrEFCore;
using HrIService;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HrService
{
	public class CFSKService : ICFSKService
	{
		private readonly MyDbContext myDbContext;
		
		public CFSKService(MyDbContext myDbContext)
        {
            this.myDbContext = myDbContext;
        }

		//根据id查询
		public async Task<CFSK> CFSKById(short FskId)
		{
			return await myDbContext.CFSK.FindAsync(FskId);
		}

		public async Task<CFFK> CFSKById2(string FirstKindId)
		{
			return await myDbContext.CFFK.FirstOrDefaultAsync(e => e.FirstKindId == FirstKindId);
		}
		//删除
		public async Task<int> CFSKDelAsync(short FskId)
		{
			CFSK cfsk = await myDbContext.CFSK.FindAsync(FskId);
			if (cfsk == null)
			{
				return 0;
			}
			myDbContext.CFSK.Remove(cfsk);
			return await myDbContext.SaveChangesAsync();
		}
		//添加
		public async Task<int> CFSKInsertAsync(CFSK cfsk)
		{
			 myDbContext.CFSK.AddAsync(cfsk);
			return await myDbContext.SaveChangesAsync();
		}
		//查看全部
		public async Task<List<CFSK>> CFSKSelectAsync()
		{
			return await myDbContext.CFSK.ToListAsync();
		}
		//修改
		public async Task<int> CFSKUpdateAsync(CFSK cfsk)
		{
			myDbContext.CFSK.Update(cfsk);
			return await myDbContext.SaveChangesAsync();
		}
	}
}
